// components/ng-rate/index.js
Component({
  properties: {
    active: {
      type: Number,
      value: 0,
      observer(newVal) {
        this.updateSum(newVal);  // 更新视图
      }
    },
    count: {
      type: Number,
      value: 5,
    },
    control: {
      type: Boolean,
      value: false,
    },
    size: {
      type: String,
      value: 'simple'
    },
    rowdata: {
      type: Object,
      value: {}
    }
  },
  data: {
    sum: 0,
  },
  methods: {
    onClickItem({
      currentTarget: {
        dataset
      }
    }) {
      const count = dataset.index + 1
      this.setData({
        sum: count
      })
      console.log(this.data.rowdata);
      this.triggerEvent('selected', {
        count,
        ...this.data.rowdata
      })
    },
    updateSum(newVal) {
      // 更新内部数据
      this.setData({
        sum: newVal
      });
    }
  },
  // 在组件挂载时调用 updateSum 来确保视图初始化时的同步
  attached() {
    this.updateSum(this.properties.active);
  }
})